﻿//-----------------------------------------------------------------------
// <copyright file="SA1101.cs" company="c0x3y">
//     Copyright (c) c0x3y. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace c0x3y.StyleCopFixer.Errors
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using EnvDTE;
    using EnvDTE80;

    public class SA1101
    {
        public static void Run(EnvDTE.DTE dte, ErrorItem error)
        {
            error.Navigate();
            EditPoint2 ep = ErrorUtilities.GetEditPoint(dte);
            ep.StartOfLine();
            string variableName = error.Description.Split(" ".ToCharArray())[4];
            string replaceString = ep.GetLines(ep.Line, ep.Line + 1);
            replaceString = Regex.Replace(replaceString, string.Format(@"(\s|\()({0})(\W)", variableName), "$1this.$2$3", RegexOptions.None);
            ep.ReplaceText(ep.LineLength, replaceString, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
        }
    }
}
